var loginModel = new Vue({
    el: '#loginModel',
    data: {
        num: "",
        pwd: "",
        isFailed: false,
        hiddenSpan: true,
        warning: '登录失败'
    },
    methods: {
        login: function () {
            loginData = {
                number: loginModel.num,
                password: loginModel.pwd
            }
            $.post('/login', loginData, function (result) {
                switch (result['result']) {
                    case 'success':
                        location.href = '/';
                        break;
                    case 'failed':
                        loginModel.hiddenSpan = false;
                        loginModel.isFailed = true;
                        break;
                    default:
                        break;
                }
            });
        }
    }
});

var mainContentObject = new Vue({
    el: '#mainContent',
    data: {
        styles: [],
        neweastMusics: [],
        topMusics: [],
        language: [],
    },
    mounted: function () {
        this.getAllStyles();
        this.getTopMusics(10);
        this.getNeweastSongs(8);
    },
    methods: {
        getAllStyles: function () {
            var url = '/song/category/get/all';
            $.get(url, function (data) {
                mainContentObject.styles = data['style'];
                mainContentObject.languages = data['language'];
            })
        },
        toStylePage: function (style) {
            console.log(style);
            location.href = '/category/page?style=' + style;
        },
        getTopMusics: function (size) {
            var url = '/song/get/top-click/size/' + size;
            $.get(url, function (data) {
                mainContentObject.topMusics = data;
            });
        },
        getNeweastSongs:function (size) {
            var url = '/song/new/'+size;
            $.get(url,function (data) {
                var l = data.slice(0, size / 2);
                var r = data.slice(size / 2, size);
                mainContentObject.neweastMusics.push(l);
                mainContentObject.neweastMusics.push(r);
            });
        }
    }
});


var searchObject = new Vue({
    el:'#searchForm',
    data:{
        keyUrl:''
    },
    methods:{
        search:function () {

        }
    }
});

var navbarSupportedContent = new Vue({
    el:'#navbarSupportedContent',
    data:{},
    methods:{
        logout:function () {
            $.get('/logout',function (result) {
                if (result['result'] == 'done') {
                    location.href = '/';
                }
            });
        }
    }
});